import { defineStore } from "pinia";

export const useUserStore = defineStore('useUserStore', {
    state(): {
        username: string
        menus: IMenu[]
    } {
        return {
            username: "",
            menus: []
        }
    },
    getters: {
        activeMenus() {
            const arr: IActiveMenus[] = this.menus.filter(item => item.parentId === 0)
            this.menus.forEach(item => {
                const p = arr.find(p => p.id === item.parentId && item.hidden === 0);
                // 判断p是否有父菜
                if (p) {
                    // 判断p中有没有chidren属性
                    if (!p.chidren) {
                        p.chidren = []
                    }
                    p.chidren.push(item)
                }
            })
            return arr
        }
    },
    actions: {}

}) 